<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.db.conn"%>
<%@ page import="com.db.Pagination"%>
<%@ page import="java.sql.*"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <jsp:include flush="true" page="${basePath}/admin/head.jsp"></jsp:include>
    <style>
        .ms-panel {
            margin: 0;
            padding: 0;
            background: #fff;
            border-radius: 4px;
            box-shadow: 0 1px 3px rgba(0,0,0,0.12);
        }
        
        .ms-panel-header {
            padding: 20px 24px;
            border-bottom: 1px solid #eee;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }
        
        .ms-panel-header h6 {
            margin: 0;
            font-size: 18px;
            font-weight: 500;
            color: #333;
        }
        
        .ms-panel-body {
            padding: 24px;
        }
        
        .category-table {
            width: 100%;
            border-collapse: collapse;
            margin-bottom: 24px;
        }
        
        .category-table th {
            background: #f8f9fa;
            color: #495057;
            font-weight: 500;
            padding: 12px 16px;
            text-align: left;
            border-bottom: 2px solid #dee2e6;
        }
        
        .category-table td {
            padding: 16px;
            border-bottom: 1px solid #eee;
            color: #333;
        }
        
        .category-table tr:hover {
            background-color: #f8f9fa;
        }
        
        .category-name {
            font-size: 15px;
            color: #333;
        }
        
        .action-buttons {
            display: flex;
            gap: 12px;
        }
        
        .btn-action {
            display: inline-flex;
            align-items: center;
            padding: 6px 12px;
            border-radius: 4px;
            font-size: 13px;
            text-decoration: none;
            transition: all 0.3s ease;
        }
        
        .btn-edit {
            background: #e3f2fd;
            color: #1976d2;
            border: 1px solid #bbdefb;
        }
        
        .btn-edit:hover {
            background: #bbdefb;
            color: #1565c0;
        }
        
        .btn-delete {
            background: #ffebee;
            color: #d32f2f;
            border: 1px solid #ffcdd2;
        }
        
        .btn-delete:hover {
            background: #ffcdd2;
            color: #c62828;
        }
        
        .pagination-container {
            display: flex;
            justify-content: center;
            margin-top: 24px;
            padding: 16px;
            background: #f8f9fa;
            border-radius: 4px;
        }
        
        .pagination {
            display: flex;
            gap: 8px;
            align-items: center;
        }
        
        .pagination a {
            padding: 6px 12px;
            border: 1px solid #dee2e6;
            border-radius: 4px;
            color: #007bff;
            text-decoration: none;
            transition: all 0.3s ease;
        }
        
        .pagination a:hover {
            background: #e9ecef;
            border-color: #dee2e6;
        }
        
        .pagination .active {
            background: #007bff;
            color: #fff;
            border-color: #007bff;
        }
        
        .pagination .disabled {
            color: #6c757d;
            pointer-events: none;
            background: #f8f9fa;
        }
    </style>
</head>

<body class="ms-body ms-aside-left-open ms-primary-theme ms-has-quickbar">
    <div class="ms-content-wrapper">
        <div class="row">
            <div class="col-md-12">
                <div class="ms-panel">
                    <div class="ms-panel-header">
                        <h6>管理小说类别信息</h6>
                    </div>
                    <div class="ms-panel-body">
                        <%
                            int pageSize = 15;
                            int pageNow = 1;
                            int rowCount = 0;
                            int pageCount = 0;
                            
                            String s_pageNow = request.getParameter("pageNum");
                            if(s_pageNow != null) {
                                pageNow = Integer.parseInt(s_pageNow);
                            }
                            
                            String where = " 1=1 ";
                            conn cn = new conn();
                            
                            ResultSet rs = cn.query("select count(*) from category a where " + where);
                            if(rs.next()) {
                                rowCount = rs.getInt(1);
                            }
                            
                            if(rowCount % pageSize == 0) {
                                pageCount = rowCount/pageSize;
                            } else {
                                pageCount = rowCount/pageSize + 1;
                            }
                            
                            rs = cn.query("select * from category a where " + where + " order by caid desc limit " + pageSize*(pageNow-1) + ", " + pageSize);
                        %>
                        
                        <table class="category-table">
                            <thead>
                                <tr>
                                    <th>类别名称</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <%
                                    while(rs.next()) {
                                %>
                                <tr>
                                    <td class="category-name"><%=rs.getString("caname") %></td>
                                    <td>
                                        <div class="action-buttons">
                                            <a href="<%=path %>/admin/category/category_Edit.jsp?id=<%=rs.getString("caid") %>" class="btn-action btn-edit">编辑</a>
                                            <a href="<%=path %>/category_Delete?id=<%=rs.getString("caid") %>" class="btn-action btn-delete" onclick="return confirm('确定要删除这个类别吗？')">删除</a>
                                        </div>
                                    </td>
                                </tr>
                                <%
                                    }
                                %>
                            </tbody>
                        </table>
                        
                        <div class="pagination-container">
                            <div class="pagination">
                                <%= Pagination.getPagination(pageNow, pageCount, rowCount, request.getRequestURI()) %>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    
    <%
        if(rs != null) rs.close();
        if(cn != null) cn.close();
    %>
</body>
</html>







